import wx
from mzSequenceView import *
from mzSequence import *

# Menu Id's
ID_ABOUT = 1000
ID_OPEN = 1001
ID_EXIT = 1002

# Tool bar Id's
ID_READING_FRAME_1 = 1003
ID_READING_FRAME_2 = 1004
ID_READING_FRAME_3 = 1005


class mzMainFrame(wx.Frame):
    def __init__(self,parent,id,title):
        wx.Frame.__init__(self,parent,wx.ID_ANY, title, size = (200,100))
        self.panel = mzSequenceView(self, wx.ID_ANY)
    
        # A StatusBar in the bottom of the window
        self.CreateStatusBar()
        
        # Create the menu bar
        self.createMenuBar()
        
        # Create the tool bar
        self.createToolBar()

        # display the whole thing
        self.Show()

    def createMenuBar(self):
        filemenu = wx.Menu()

        filemenu.Append(ID_OPEN, "&Open", " Opens a DNA sequence file (*.seq)")
        wx.EVT_MENU(self, ID_OPEN, self.onOpen)
        filemenu.AppendSeparator()

        filemenu.Append(ID_EXIT, "E&xit", " Terminate the program")
        wx.EVT_MENU(self, ID_EXIT, self.onExit)   # attach the menu-event ID_EXIT to the
                                                # method self.OnExit

        # Creating the menu bar.
        menuBar = wx.MenuBar()
        menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
        self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.
    
    def createToolBar(self):
        self.toolbar = self.CreateToolBar()
        
        icon = wx.Bitmap("one.bmp", wx.BITMAP_TYPE_BMP)
        self.toolbar.AddRadioTool(ID_READING_FRAME_1, icon, icon)
        wx.EVT_TOOL(self, ID_READING_FRAME_1, self.onReadingFrame1)

        self.toolbar.AddRadioTool(ID_READING_FRAME_2, icon, icon)
        wx.EVT_TOOL(self, ID_READING_FRAME_2, self.onReadingFrame2)

        self.toolbar.AddRadioTool(ID_READING_FRAME_3, icon, icon)
        wx.EVT_TOOL(self, ID_READING_FRAME_3, self.onReadingFrame3)
        
        self.toolbar.Realize()

    def onOpen(self, event):
        fd = wx.FileDialog(self)
        if wx.ID_OK == fd.ShowModal():
            self.panel.sequence = mzSequence(fd.GetPath())
            self.panel.Refresh()
            self.panel.Update()
            
        
    def onExit(self, event):
        self.Close(True)
        
    def onReadingFrame1(self, event):
        self.panel.sequence.readStart = 3
        self.Refresh()
        self.Update()
            
    def onReadingFrame2(self, event):
        self.panel.sequence.readStart = 1
        self.Refresh()
        self.Update()
            
    def onReadingFrame3(self, event):
        self.panel.sequence.readStart = 2
        self.Refresh()
        self.Update()
        